<?php
echo "Hello world";
// ... more code
echo "Last statement";?>
<?php
echo "Hello world";
// ... more code
echo "Last statement";
<?php
    echo "This is a test";
    echo '最后一行可以不用分号'
?>
<?php
    echo "This is a test"; // 这是一个 c++ 风格的注释
    /* 这是多行注释
       多行注释 */
    echo "This is yet another test";
    echo 'One Final Test'; # 这是Shell风格的单行注释
?>
<?php
if ($a > $b) {
  echo "a is bigger than b";
  $b = $a;
}
?>
<?php
if ($a > $b) {
  echo "a is greater than b";
} else {
  echo "a is NOT greater than b";
}
?>
<?php
if ($a > $b) {
    echo "a is bigger than b";
} elseif ($a == $b) {
    echo "a is equal to b";
} else {
    echo "a is smaller than b";
}
?>
<?php
switch ($i) {
case "apple":
    echo "i is apple";
    break;
case "bar":
    echo "i is bar";
    break;
case "cake":
    echo "i is cake";
    break;
}
<?php
function foo($arg_1, $arg_2, /* ..., */ $arg_n)
{
    echo "Example function.\n";
    return $retval;
}
?>
<?php
function add_some_extra(&$string)
{
    $string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str;    // outputs 'This is a string, and something extra.'
?>
<?php
function makecoffee($type = "cappuccino")
{
    return "Making a cup of $type.\n";
}
echo makecoffee();
echo makecoffee(null);
echo makecoffee("espresso");
?>